import random
import time
import copy
import os
from tracemalloc import start
from BubbleSort import BubbleSort
from SelectionSort import SelectionSort
from InsertionSort import InsertionSort
from ShellSort import ShellSort
from MergeSort import MergeSort
from QuickSort import QuickSort
from RandomQuickSort import RandomQuickSort

os.system('cls')
ls_temp = [random.randint(0,10000) for i in range(10000)]

# # 冒泡排序
# myBubbleSort = BubbleSort()
# ls = copy.copy(ls_temp)
# print('冒泡排序:')
# print(f'\t排序前是否有序{myBubbleSort.isSorted(ls)}')
# start_time = time.time()
# myBubbleSort.sort(ls)

# print(f'\t排序成功{myBubbleSort.isSorted(ls)}')
# print(f'\t交换次数{myBubbleSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')


# # 选择排序
# mySelectionSort = SelectionSort()
# ls = copy.copy(ls_temp)
# print('选择排序:')
# print(f'\t排序前是否有序{mySelectionSort.isSorted(ls)}')
# start_time = time.time()
# mySelectionSort.sort(ls)
# print(f'\t排序成功{mySelectionSort.isSorted(ls)}')
# print(f'\t交换次数{mySelectionSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')

# # 插入排序
# myInsertionSort = InsertionSort()
# ls = copy.copy(ls_temp)
# print('插入排序:')
# print(f'\t排序前是否有序{myInsertionSort.isSorted(ls)}')
# start_time = time.time()
# myInsertionSort.sort(ls)
# print(f'\t排序成功{myInsertionSort.isSorted(ls)}')
# print(f'\t交换次数{myInsertionSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')

# # 希尔排序
# myShellSort = ShellSort()
# ls = copy.copy(ls_temp)
# print('希尔排序:')
# print(f'\t排序前是否有序{myShellSort.isSorted(ls)}')
# start_time = time.time()
# myShellSort.sort(ls)
# print(f'\t排序成功{myShellSort.isSorted(ls)}')
# print(f'\t交换次数{myShellSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')

# # 归并排序
# myMergeSort = MergeSort()
# ls = copy.copy(ls_temp)
# print('归并排序:')
# print(f'\t排序前是否有序{myMergeSort.isSorted(ls)}')
# start_time = time.time()
# mergels = myMergeSort.sort(ls)
# print(f'\t排序成功{myMergeSort.isSorted(mergels)}')
# print(f'\t交换次数{myMergeSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')

# # 快速排序
# myQuickSort = QuickSort()
# ls = copy.copy(ls_temp)
# print('快速排序:')
# print(f'\t排序前是否有序{myQuickSort.isSorted(ls)}')
# start_time = time.time()
# myQuickSort.sort(ls,0,len(ls)-1)
# print(f'\t排序成功{myQuickSort.isSorted(ls)}')
# print(f'\t交换次数{myQuickSort.count}')
# print(f'\t用时{round(time.time()-start_time,10)}s')

# 快速排序
myRandomQuickSort = RandomQuickSort()
ls = copy.copy(ls_temp)
print('随机快速排序:')
print(f'\t排序前是否有序{myRandomQuickSort.isSorted(ls)}')
start_time = time.time()
myRandomQuickSort.sort(ls,0,len(ls)-1)
print(f'\t排序成功{myRandomQuickSort.isSorted(ls)}')
print(f'\t交换次数{myRandomQuickSort.count}')
print(f'\t用时{round(time.time()-start_time,10)}s')


